//
//  RBShopApplyPageStep2VC.m
//  zhongzhenglu
//
//  Created by mac on 2022/10/24.
//

#import "RBShopApplyPageStep2VC.h"
#import "RBDefine.h"
#import "UIView+RBAdd.h"
#import "UIScrollView+RBAdd.h"
#import "RBThemeConfig.h"
#import <Masonry.h>
#import "RBNavigationBar.h"
#import "RBTextField.h"
#import "UIButton+RBAdd.h"
#import <UIColor+YYAdd.h>
#import "UIViewController+RBAdd.h"
#import <UINavigationController+FDFullscreenPopGesture.h>
#import "RBGradientView.h"

@interface RBShopApplyPageStep2VC ()

@property(nonatomic, strong) RBNavigationBar *navigationBar;
@property(nonatomic, strong) UITextField *accountF;
@property(nonatomic, strong) UITextField *bankF;
@property(nonatomic, strong) UITextField *pubAccountF;

@end

@implementation RBShopApplyPageStep2VC

#pragma mark - Lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self setup];
    [self fillData];
}

#pragma mark - Private

- (void)setup
{
    self.fd_prefersNavigationBarHidden = YES;
    RBGradientView *topBgView = [RBGradientView gradientViewWithColors:@[[UIColor colorWithHexString:@"#CADCFF"],[UIColor colorWithHexString:@"#E8F0FF"]] locations:nil vertical:YES];
    [self.view addSubview:topBgView];
    [topBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.mas_equalTo(0);
        make.height.mas_equalTo(kRBStatusBarHeight + kRBNavigationBarHeight + Zoom(150));
    }];
    self.navigationBar.hidden = NO;
    
    if(self.response.data.status == 2)
    {
        UIAlertController *vc = [UIAlertController alertControllerWithTitle:@"审核失败,请重新提交" message:self.response.data.fail_reason preferredStyle:UIAlertControllerStyleAlert];
        [vc addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            
        }]];
        [self presentViewController:vc animated:YES completion:nil];
    }
}

- (void)fillData
{
    UIView *statusView = ({
        UIView *view = UIView.new;
        NSArray *imgs = @[@"shopApplyPass",@"shopApplyPass",@"",@"",@""];
        NSArray *names = @[@"注册成功",@"审核通过",@"财务审核",@"保证金审核",@"合同审核"];
        for (NSInteger i = 0; i < imgs.count; i++)
        {
            [view h_view_addView:({
                UIView *view = UIView.new;
                [view view_addView:({
                    UIView *view = UIView.new;
                    view.backgroundColor = [UIColor colorWithHexString:@"#518CFF"];
                    [view rbSetCornerRadius:Zoom(19)];
                    NSString *imgName = imgs[i];
                    if(imgName.length)
                    {
                        UIImageView *imgView = [RanTool imgViewWithMode:1 radius:0 imgName:imgs[i]];
                        [view addSubview:imgView];
                        [imgView mas_makeConstraints:^(MASConstraintMaker *make) {
                            make.center.mas_equalTo(0);
                            make.width.mas_equalTo(Zoom(17));
                            make.height.mas_equalTo(Zoom(14));
                        }];
                    }
                    view;
                }) withHeight:Zoom(38) width:Zoom(38) top:0 bottom:CGFLOAT_MIN left:0 right:0 centerX:1];
                [view view_addView:[RanTool labelWithFontSize:Zoom(13) weight:0 color:@"#454545" align:1 text:names[i]] withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:CGFLOAT_MIN bottom:0 left:0 right:0 centerX:0];
                view;
            }) withHeight:CGFLOAT_MIN width:kRBMainScreenWidth/imgs.count top:0 bottom:0 left:0 right:CGFLOAT_MIN centerY:0];
        }
        view;
    });
    [self.view addSubview:statusView];
    [statusView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(kRBStatusBarHeight + kRBNavigationBarHeight + Zoom(30));
        make.height.mas_equalTo(Zoom(67));
    }];
    UIScrollView *scrollView = UIScrollView.new;
    [self.view addSubview:scrollView];
    [scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.top.mas_equalTo(kRBStatusBarHeight + kRBNavigationBarHeight + Zoom(140));
    }];
    [scrollView rbSetContentWidth:kRBMainScreenWidth];
    [scrollView addView:({
        UIView *view = UIView.new;
        view.backgroundColor = UIColor.whiteColor;
        [view rbSetCorner:UIRectCornerTopLeft | UIRectCornerTopRight radius:Zoom(15)];
        [view view_addView:[RanTool labelWithFontSize:Zoom(18) weight:2 color:@"333333" align:1 text:@"请填写财务信息"] withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:Zoom(44) bottom:CGFLOAT_MIN left:Zoom(12) right:Zoom(12) centerX:NO];
        [view view_addView:({
            UIView *view = UIView.new;
            [view h_view_addView:[RanTool labelWithFontSize:Zoom(16) weight:0 color:@"454545" align:0 text:@"账户名称"] withHeight:CGFLOAT_MIN width:Zoom(80) top:0 bottom:0 left:0 right:0 centerY:0];
            UITextField *textF = UITextField.new;
            self.accountF = textF;
            textF.font = [UIFont systemFontOfSize:Zoom(16)];
            textF.backgroundColor = [UIColor colorWithHexString:@"#F5F5F5"];
            [view h_view_addView:textF withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:0 right:0 centerY:0];
            view;
        }) withHeight:Zoom(32) width:CGFLOAT_MIN top:Zoom(40) bottom:CGFLOAT_MIN left:Zoom(27) right:Zoom(21) centerX:0];
        [view view_addView:({
            UIView *view = UIView.new;
            [view h_view_addView:[RanTool labelWithFontSize:Zoom(16) weight:0 color:@"454545" align:0 text:@"开户银行"] withHeight:CGFLOAT_MIN width:Zoom(80) top:0 bottom:0 left:0 right:0 centerY:0];
            UITextField *textF = UITextField.new;
            self.bankF = textF;
            textF.font = [UIFont systemFontOfSize:Zoom(16)];
            textF.backgroundColor = [UIColor colorWithHexString:@"#F5F5F5"];
            [view h_view_addView:textF withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:0 right:0 centerY:0];
            view;
        }) withHeight:Zoom(32) width:CGFLOAT_MIN top:Zoom(15) bottom:CGFLOAT_MIN left:Zoom(27) right:Zoom(21) centerX:0];
        [view view_addView:({
            UIView *view = UIView.new;
            [view h_view_addView:[RanTool labelWithFontSize:Zoom(16) weight:0 color:@"454545" align:0 text:@"对公账户"] withHeight:CGFLOAT_MIN width:Zoom(80) top:0 bottom:0 left:0 right:0 centerY:0];
            UITextField *textF = UITextField.new;
            self.pubAccountF = textF;
            textF.font = [UIFont systemFontOfSize:Zoom(16)];
            textF.backgroundColor = [UIColor colorWithHexString:@"#F5F5F5"];
            [view h_view_addView:textF withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:0 right:0 centerY:0];
            view;
        }) withHeight:Zoom(32) width:CGFLOAT_MIN top:Zoom(15) bottom:0 left:Zoom(27) right:Zoom(21) centerX:0];
        [view view_addView:({
            UILabel *view = [RanTool labelWithFontSize:Zoom(18) weight:0 color:UIColor.whiteColor align:1 text:@"提交" bgColor:@"#518CFF" radius:Zoom(22)];
            [view rbAddTapGesWithTarget:self action:@selector(submitBtnTapped)];
            view;
        }) withHeight:Zoom(44) width:Zoom(314) top:Zoom(44) bottom:Zoom(40) left:0 right:0 centerX:1];
        view;
    }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:0 right:0 centerX:0];
}

#pragma mark - Network

#pragma mark - Event

- (void)submitBtnTapped
{
    if(!self.accountF.text.length)
    {
        [self.view showTip:@"请输入账户名称" completion:nil];
        return;
    }
    if(!self.bankF.text.length)
    {
        [self.view showTip:@"请输入开户银行" completion:nil];
        return;
    }
    if(!self.pubAccountF.text.length)
    {
        [self.view showTip:@"请输入对公账户" completion:nil];
        return;
    }
    __weak typeof(self) weak_self = self;
    [self viewLoadDataWithParam:^(NSMutableDictionary *dicM) {
        dicM[@"company_bank_name"] = self.accountF.text;
        dicM[@"company_bank_addr"] = self.bankF.text;
        dicM[@"company_bank_code"] = self.pubAccountF.text;
        dicM[@"store_id"] = self.response.data.store_id;
    } path:@"han_store_step2" post:YES log:YES responseClass:RBResponse.class desView:self.view showHud:YES showPlaceHolder:NO sucBlock:^(RBResponse *data) {
        [weak_self.view showTip:@"信息已提交,请等待审核" completion:^{
            [weak_self.navigationController popViewControllerAnimated:YES];
        }];
    } failBlock:^(RBResponse *data) {
        [weak_self.view showTip:data.message completion:nil];
    } reloadBlock:nil];
}

#pragma mark - Setter

#pragma mark - Getter

- (RBNavigationBar *)navigationBar
{
    if (!_navigationBar)
    {
        self.navigationBar = ({
            RBNavigationBar *bar = RBNavigationBar.new;
            bar.needGradientView = NO;
            [self.view addSubview:bar];
            [bar mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.top.right.mas_equalTo(0);
                make.height.mas_equalTo(kRBStatusBarHeight + kRBNavigationBarHeight);
            }];
            [bar.naviBar addBackBtnWithWidth:70 image:[UIImage imageNamed:@"backBlack"]];
            {
                UILabel *view = [RanTool labelWithFontSize:18 weight:0 color:@"222222" align:0 text:@"财务审核"];
                [bar.naviBar addSubview:view];
                [view mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.center.mas_equalTo(0);
                }];
            }
            bar;
        });
    }
    return _navigationBar;
}

@end
